//
//  BaseTableViewController.swift
//  WeiBo
//
//  Created by 刘星 on 16/6/6.
//  Copyright © 2016年 LiuXing. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController {

    var userLogin = UserAccount.userLgoin()
    var visitorView: ViristorView?
    override func loadView() {
        userLogin ? super.loadView() : setupVisitorView()
    }
    /// 未登录界面
    private func setupVisitorView() {
        let customView = ViristorView()
        customView.delegate = self
        view = customView
        visitorView = customView
        // 
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(BaseTableViewController.registerButtonWillClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(BaseTableViewController.loginButtonWillClick))
    }
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

extension BaseTableViewController: ViristorViewDelegate {
    func loginButtonWillClick() {
        print(#function)
        let oauthVC = OAuthViewController()
        let nav = UINavigationController(rootViewController: oauthVC)
        presentViewController(nav, animated: true, completion: nil)
    }
    func registerButtonWillClick() {
        print(#function)
        print(UserAccount.loadAccount())
    }
}